<?php

namespace App\Jobs\Circle;

use App\Models\Posts\WxUserCircle;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Cache;

class ForgetCircleUnreadCountJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
    protected $circle_id = 0;
    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct($circle_id)
    {
        //
        $this->circle_id = $circle_id;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        //
        if(_empty_($this->circle_id)){
            return;
        }
        $user_ids = WxUserCircle::where('circle_id', $this->circle_id)->where('user_circle_state', 0)->pluck('user_id')->toArray();
        if($user_ids){
            foreach ($user_ids as $user_id){
                Cache::forget('user_circle_unread_count:'.$user_id);
            }
        }
    }
}
